package nl.jjsoft.airlock.controller
{
	import flash.data.SQLMode;
	import flash.filesystem.File;
	import flash.utils.ByteArray;
	
	import mx.controls.Alert;
	
	import nl.jjsoft.airlock.SqlDB;
	import nl.jjsoft.airlock.utils.PasswordGenerator;
	
	public class LoginController implements ILoginController // extends AbstractController
	{
		public function LoginController() {	}
		
		public function dbExists(dbPath:String):Boolean {
			return new File(dbPath).exists;						
		}
		
		public function loginToPasswordDB(dbPath:String, safeCombination:String):Boolean {
			var dbFile:File = new File(dbPath);
			var key:ByteArray = PasswordGenerator.getEncryptionKey(safeCombination);
			var db:SqlDB = new SqlDB();
			
			var loginSuccess:Boolean = false;
			try {
				loginSuccess = db.connect(dbFile, key);
			} finally {
				db.disconnect();
			}					
			
			return loginSuccess;
		}
		
		public function isKeySecure(key:String):Boolean {
			return PasswordGenerator.isKeySecure(key);
		}
	}
}